import React, { Context, useState } from "react"
export interface AppProviderProps {
  queryFilter?: {
    layout?: 'vertical' | 'horizontal' | 'inline'
    colNum?: number,
    reset?: boolean
  }
  children?: React.ReactNode
  /**
   * 请求对象
   */
  request?: any
  /**
   * 公共头部
   */
  commonHeaders?: {},
  /**
   * api前缀
   */
  apiPrefix?: string
  /**
   * 上传参数
   */
  upload?: {
    action: string
    fileKey?:string
  }
  richText?:{
    fileUrlResultFormat:(res:any)=>string
  }
  fileBasicUrl?: string
  permission?:any
  setPermission?:any
  antdList?: {
    page?: {
      total?:string
      records?:string
      key?: string
      size?: string
      current?: string
    }
  }

}

const AppContextKey = `__WebDesinAppContextReact_${React.version}`

if (!(window as any)[AppContextKey]) {
  (window as any)[AppContextKey] = React.createContext<AppProviderProps>({})
}
export const AppContext = (window as any)[AppContextKey] as Context<AppProviderProps>;

const AppProvider = ({ children, ...rest }: AppProviderProps) => {
  const [permission,setPermission] = useState({});
  return <AppContext.Provider value={{...rest,permission,setPermission}}>
    {children}
  </AppContext.Provider>
}
export default AppProvider